import http from "@/utils/http";
import { headerCommon, headerMaster } from "../header";
import { MaterialSearchData, PaginationType, MaterialAddData } from "./params";
import { MaterialListResData, MaterialResData } from "./res";

enum API {
    GET_MATERIAL_LIAT_API = '/1.1/classes/material',
    DELETE_MATERIAL_API = '/1.1/classes/material',
    POST_MATERIAL_ADD_API = "/1.1/classes/material",
    GET_MATERIAL_DETAIL_API = '/1.1/classes/material',
    PUT_MATERIAL_UPDATE_API = '/1.1/classes/material',
}

// 获取物料列表
export const getMaterialListApi = (data?: MaterialSearchData, params?: PaginationType) =>
    http.get<any, MaterialListResData>(API.GET_MATERIAL_LIAT_API + `${data ? `?where=${JSON.stringify(data)}` : ""}`, {
        headers: headerCommon,
        ...(params ? { params: { limit: params.pageSize, skip: (params.currentPage - 1) * params.pageSize } } : {})
    })

// 删除物料
export const deleteMaterialApi = (objectId: string) =>
    http.delete<any, any>(API.DELETE_MATERIAL_API + `/${objectId}`, {
        headers: headerMaster
    })

export const postMaterialAddApi = (data: MaterialAddData) =>
    http.post<any, any>(API.POST_MATERIAL_ADD_API, data, { headers: headerCommon })

export const getMaterialDetailApi = (objectId: string) =>
    http.get<any, MaterialResData>(API.GET_MATERIAL_DETAIL_API + `/${objectId}`, {
        headers: headerCommon,
    })

export const putMaterialUpdateApi = (data: MaterialAddData) =>
    http.put<any, any>(API.PUT_MATERIAL_UPDATE_API + `/${data.objectId}`, data, {
        headers: headerMaster
    })